/*package jaxb.cow;

import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.kedacom.sales.contract.util.CommonUtil;
import com.kedacom.sales.contract.util.PathUtils;
import com.kedacom.sales.util.ReflectUtils;

*//**
 * 处理Excel的公共类,本类读取映射文件来读取或者写入Excel文件
 * @author 沈俊杰
 * @date 2014-6-2
 * @version 1.0
 *//*
public class ExcelMappingUtils 
{
    private static Log log = LogFactory.getLog(ExcelMappingUtils.class);
    
    public final static String EXCEL_2007_SUFFIX = ".xlsx,.xlsm";
    
    public final static String EXCEL_2003_SUFFIX = ".xls";
    
    public final static int EXCEL_2007 = 2007;
    
    public final static int EXCEL_2003 = 2003;
    
    public final static int colReadMax = 100;
    
    public final static int rowReadMax = 500;
    
    public final static String outputDir = "export_file";
    
    *//**
     * <p>根据配置文件,将Excel文件的内容读到对象中</p>
     * <p>默认文件路径为PathUtils.getExcelTemplatePath()</p>
     * <p>默认配置文件名为Excel文件名后面加"mapping"</p>
     * <p>默认Excel文件和配置文件在同一个目录</p>
     * @param excelFileName excel文件名称
     * @author shenjunjie
     * @date [2014-7-3]
     *//*
    public static Object readToObj(String excelFileName)
    {
        if (StringUtils.isBlank(excelFileName))
        {
            return null;
        }
        String xmlFileNamePrefix = excelFileName.substring(0, excelFileName.lastIndexOf("."));
        StringBuffer configFileName = new StringBuffer(xmlFileNamePrefix);
        configFileName.append("_mapping");
        configFileName.append(".xml");
        return readToObj(excelFileName, configFileName.toString());
    }
    
    *//**
     * <p>根据配置文件,将Excel文件的内容读到对象中</p>
     * <p>默认文件路径为PathUtils.getExcelTemplatePath()</p>
     * <p>默认Excel文件和配置文件在同一个目录</p>
     * @param excelFileName excel文件名称
     * @param configFileName 配置文件名称
     * @author shenjunjie
     * @date [2014-7-3]
     *//*
    public static Object readToObj(String excelFileName, String configFileName)
    {
        if (StringUtils.isBlank(excelFileName) || StringUtils.isBlank(excelFileName))
        {
            return null;
        }
        String fileDir = PathUtils.getExcelTemplatePath();
        File file = new File(fileDir + File.separator + excelFileName);
        File configFile = new File(fileDir + File.separator + configFileName);
        return readToObj(file, configFile);
    }
    
    *//**
     * <p>根据配置文件,将Excel文件的内容读到对象中</p>
     * @param excelFileName excel文件对象
     * @param configFileName 配置文件对象
     * @author shenjunjie
     * @date [2014-7-3]
     *//*
    public static Object readToObj(File excelFile, File configFile)
    {
        if (excelFile == null || !excelFile.exists() || configFile == null || !configFile.exists())
        {
            log.warn("Excel文件或映射配置文件不存在!");
            return null;
        }
        try
        {
            ExcelMappingSheet sheetConfig = ExcelConfigReader.readByJaxb(configFile);
            if (sheetConfig != null && StringUtils.isNotBlank(sheetConfig.getClassName()))
            {
                Class<?> c = Class.forName(sheetConfig.getClassName());
                Object o = c.newInstance();
                Workbook book = null;
                FileInputStream fis = null;
                
                int excelType = ExcelUtils.getExcelType(excelFile);
                fis = new FileInputStream(excelFile);
                if (EXCEL_2003 == excelType)
                {
                    book = new HSSFWorkbook(fis);
                }
                 暂时不用支持 2007 格式
                else {book = new XSSFWorkbook(fis);}
                if (null != book)
                {
                    //读取工作表
                    Sheet sheet = book.getSheetAt(sheetConfig.getSheetNo() - 1);
                    //处理普通单元格
                    handleUnits(o, sheet, sheetConfig.getUnits(), null);
                    //处理集合区域
                    handleZone(o, sheet, sheetConfig.getZones());
                }
                return o;
            }
        }
        catch (Exception e)
        {
            log.error(e);
        }
        return null;
    }
    
    *//**
     * <p>处理普通的单元格</p>
     * @param o 要set值的对像
     * @param sheet 取值的sheet,如果要处理的单元格都在同一行,则可以为null
     * @param configSheet 对应关系配置
     * @param row 如果要设置的单元格分散在不同的行里面,可以为null;如果都在同一行中,就传入改行.
     * @author shenjunjie
     * @date [2014-6-25]
     *//*
    private static Object handleUnits(Object o, Sheet sheet, List<ExcelMappingUnit> units, Row row)
    {
        if (CollectionUtils.isNotEmpty(units))
        {
            if (sheet == null && row == null)
            {
                //这两个至少有一个不为null
                return null;
            }
            boolean rowFix = false;
            if(row != null){
                rowFix = true;
            }
            //统计空单元格数量
            int blankCount = 0;
            for (ExcelMappingUnit unit : units)
            {
                //根据每一个单元格的配置,将值写入到对象的字段中
                if (!rowFix)
                {
                    row = sheet.getRow(unit.getCellY() - 1);
                }
                Cell cell = row.getCell(unit.getCellXInt());
                int cellType = cell.getCellType();
                if (cellType == Cell.CELL_TYPE_BLANK)
                {
                    blankCount++;
                    continue;
                }
                if("guaranteePeriod".equals(unit.getField())){
                    System.out.println();
                }
                String cellValue = cell.getStringCellValue();
                String fieldValue = getFieldValueByUnit(cellValue,unit);
                ReflectUtils.setFieldValue(o, unit.getField(), fieldValue);
            }
            if (rowFix && blankCount == units.size())
            {
                //如果是区域模式(行固定),读到所有的单元格都是空白则判断该行是空行;
                return null;
            }
        }
        return o;
    }
    
    *//**
     * <p>功能简述</p>
     * <p>根据"总共${field1}个月",构造一个正则表达式"总共.+个月",满足这个正则,系统才会开始解析</p>
     * <p>经过上步,字符窜格式就被限定为"总共xxxx个月",然后在构造正则"[^总共][^个月]"</p>
     * <p>最后就能解析出xxxx</p>
     * @param cellValue
     * @param unit
     * @return [参数说明]
     * @author shenjunjie
     * @date [2014-7-1]
     *//*
    public static String getFieldValueByUnit(String cellValue, ExcelMappingUnit unit)
    {
        if (StringUtils.isNotEmpty(cellValue) && StringUtils.isNotEmpty(unit.getExpression())
                && !unit.getExpression().equals(ExcelConfigReader.getExpression(unit.getField())))
        {
            String fieldValue = CommonUtil.parseStrByPattern(unit.getExpression(), cellValue);
            return fieldValue;
        }
        return cellValue;
    }

    private static void handleZone(Object o, Sheet sheet, List<ExcelMappingZone> zones)
    {
        if (o != null && CollectionUtils.isNotEmpty(zones))
        {
            for (ExcelMappingZone zoneConfig : zones)
            {
                try
                {
                    String field = zoneConfig.getField();
                    //根据配置读取字段的类型
                    Type t = ReflectUtils.getFieldType(o.getClass(), field);
                    if (t == null)
                    {
                        continue;
                    }
                    else if (t instanceof ParameterizedType)
                    {
                        //进到这里的一般是带有泛型的类
                        //取出类的类型
                        Class<?> rawClass = (Class<?>)((ParameterizedType)t).getRawType();
                        if (List.class.isAssignableFrom(rawClass))
                        {
                            List list = new ArrayList();
                            //取出泛型类型
                            Type[] ts = ((ParameterizedType)t).getActualTypeArguments();
                            //纵向最大值
                            Integer yMax = zoneConfig.getEndY();
                            if (yMax == null)
                            {
                                yMax = 9999;
                            }
                            //从配置的纵坐标开始读行,直到读到空行为止
                            rowLoop: for (int y = (zoneConfig.getStartY() - 1); y < yMax; y++)
                            {
                                Row row = sheet.getRow(y);
                                if (row.getPhysicalNumberOfCells() == 0)
                                {
                                    //读到空行则终止
                                    break rowLoop;
                                }
                                //每读到一行,构造一个对象放入list
                                Object listObj = ((Class<?>)ts[0]).newInstance();
                                listObj = handleUnits(listObj, null, zoneConfig.getUnits(), row);
                                if (listObj != null)
                                {
                                    list.add(listObj);
                                }
                                else
                                {
                                    break rowLoop;
                                }
                            }
                            ReflectUtils.setFieldValue(o, field, list);
                        }
                        else if (Set.class.isAssignableFrom(rawClass))
                        {
                            
                        }
                    }
                    else if (t instanceof GenericArrayType)
                    {
                        //暂未实现
                    }
                }
                catch (Exception e)
                {
                    log.warn(e);
                }
            }
        }
    }
    
}
*/